<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.tjtt.common.utils.StringUtil"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html>
  <head>
  <base target="_self"/>
  
  <title>子表基本信息修改页面</title>
  	<meta http-equiv="X-UA-Compatible" content="IE=7" />
  	<%@ include file="../jslib/jquerylib.jsp" %>
    <link rel="stylesheet" type="text/css" href="<%=path %>/web/style/layout.css" />
    <script type="text/javascript" src="<%=path %>/jqGrid/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<%=path %>/jslib/jquery.validate.min.js"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/additional-methods.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/demo.css">
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if>
    <script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    $().ready(function() {
	$("#pageFrom").validate({
		onkeyup :false,onclick:false,
			rules: {
				buttonName: {
				      required: true,
				      withoutspecial: true,
				      maxlength:40
				}
			},
		messages: {
			buttonName: {
			      required: "子表名称不能为空",
			      maxlength: "内容过长",
			      withoutspecial : "字符违规"
			}
		},  
	   /* 重写错误显示消息方法,以alert方式弹出错误消息 */  
	   showErrors : function(errorMap, errorList) {
		    var msg = "";  
		    $.each(errorList, function(i, v) {  
		     msg = (v.message + "\r\n");  
		    
		    if (msg != ""){  
		     alert(msg);
		     return false;  
		     }
		     });  
		   onfocusout=false; 
	   }
	  });  
			
				
    	// 准备好Options对象
    	var options = {
    	    url:'<%=request.getContextPath() %>/submitUpdateAutoFormButton.action',
    	    beforeSubmit: function() {
    			return $('#pageFrom').form('enableValidation').form('validate');
    		},
    	    dataType:'json',
    	    success: function(data) {
    	      if(data.result=='success'){
				alert("修改成功");
				api.get('cerify').refresh();
				api.close();
				W.refreshIt();
    	      }else{
    	      	alert("系统繁忙，请您稍后再试！");
    	      	api.close();
				W.refreshIt();
    	      }
    	}};
    	
		$('#saveBtn').click(function(){
			$('#pageFrom').ajaxSubmit(options);
			return false;
		});
		
		$('#closeBtn').click(function(){
			api.close();
		});
	});

	function countlen(textarea){
	    if (textarea.value.length> 250){
	        alert("最多为250个字符,字符输入超出限制!");
	        textarea.value=textarea.value.substring(0,250);
	    }
	    return true;
	}
	
	  //选择被关联表单名称和id
		function chooseByTableName(){
	     var datas = window.showModalDialog("<%=basePath%>/auto/choose_foreign_table_name.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
				if(typeof(datas) == 'undefined'){
				}else{
					callbackByTableName(eval('(' + datas + ')'));
				}
		 jQuery("#byTableColumn").val("");		
       }
        //被关联表单名称和id回调赋值
       function callbackByTableName(json){
 			$("#byTableName").val(json.form_en_name);
 			$("#byTableNameId").val(json.formId);
	   }
	   
	   
	   //选择被关联表单名称字段
	   function chooseByTableCloumn(){
	   		var byTableNameId = $("#byTableNameId").val();
	   		if(byTableNameId == ""){
	   			alert("请先选择被关联表单名称！");
	   			return false;
	   		}
  			var datas = window.showModalDialog("<%=basePath%>/auto/choose_foreign_cloumn.jsp?formId="+byTableNameId+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
			if(typeof(datas) == 'undefined'){
			}else{
				callbackByTableCloumn(datas);
			}
	   }
	    //被关联表单名称回调赋值
       function callbackByTableCloumn(json){
 			$("#byTableColumn").val(json);
	   }
	   
	   
	   
	    //选择本关联表单字段
	   function chooseThisTableCloumn(){
	   		var thisTableNameId = $("#thisTableNameId").val();
  			var datas = window.showModalDialog("<%=basePath%>/auto/choose_foreign_cloumn.jsp?formId="+thisTableNameId+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=1000px;dialogHeight=500px");
			if(typeof(datas) == 'undefined'){
			}else{
				callbackThisTableCloumn(datas);
			}
	   }
	   //本关联表单字段回调赋值
	   function callbackThisTableCloumn(json){
 			$("#thisTableColumn").val(json);
	   }
	   
	   
</script>

 <style type="text/css">
	body{
		background:#ffffff; background-image:url(images/);
	}
</style>
</head>
<body>
  	<form action="" id="pageFrom" name="" method="post" class="easyui-form" data-options="novalidate:true">
  	<input type="hidden" id="buttonId" name="buttonId" value="${buttonObj[0] }"/>
  		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
		  <tr>
		    <td align="right">子表名称：</td>
		    <td align="left">
				<input type="text" id="buttonName" name="buttonName" value="${buttonObj[1] }"/>
				<img src="<%=request.getContextPath() %>/images/xh.png"></img>
		    </td>
		  </tr>
		  <tr>
		    <td align="right">本关联表单名称：</td>
		    <td align="left">
		    	<input type="hidden" id="thisTableNameId" name="thisTableNameId" readonly="readonly" value="${buttonObj[6] }"/>
				<input type="text" id="thisTableName" name="thisTableName" readonly="readonly" value="${buttonObj[7] }"/>
		    </td>
		  </tr>
		  <tr>
		    <td align="right">本关联表单字段：</td>
		    <td align="left">
				<input type="text" readonly="readonly" id="thisTableColumn" name="thisTableColumn" value="${buttonObj[8] }"/>
				&nbsp;&nbsp;<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseThisTableCloumn();" title="选择" style="margin-bottom:5px;cursor:hand;" />
		    </td>
		  </tr>
		  <tr>
		    <td align="right">被关联表单名称：</td>
		    <td align="left">
				<input type="text" readonly="readonly" id="byTableName" name="byTableName" value="${buttonObj[11] }"/>
				<input type="hidden" id="byTableNameId" name="byTableNameId" value="${buttonObj[4]}"/>
				&nbsp;&nbsp;<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseByTableName();" title="选择" style="margin-bottom:5px;cursor:hand;" />
		    </td>
		  </tr>
		  <tr>
		    <td align="right">被关联表单字段：</td>
		    <td> 
				<input readonly="readonly" type="text" id="byTableColumn" name="byTableColumn" value="${buttonObj[2]}"/>
				&nbsp;&nbsp;<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" width="23" height="23" border="0" onclick="chooseByTableCloumn();" title="选择" style="margin-bottom:5px;cursor:hand;" />
		    </td>
		  </tr>
		  <tr>
		    <td align="right">子表类型：</td>
		    <td> 
		    	<select name="buttonType" id="buttonType" style="width:155px;">
		    		<option value="0" <c:if test="${buttonObj[9] == '0' }">selected=selected</c:if>>按钮</option>
		    		<!-- <option value="1" <c:if test="${buttonObj[9] == '1' }">selected=selected</c:if>>列表</option>
		    		<option value="2" <c:if test="${buttonObj[9] == '2' }">selected=selected</c:if>>原始记录</option>
		    		<option value="5" <c:if test="${buttonObj[9] == '5' }">selected=selected</c:if>>军检原始记录</option>
		    		<option value="3" <c:if test="${buttonObj[9] == '3' }">selected=selected</c:if>>合格证</option>
		    		<option value="4" <c:if test="${buttonObj[9] == '4' }">selected=selected</c:if>>记录单</option>
		    		<option value="6" <c:if test="${buttonObj[9] == '6' }">selected=selected</c:if>>选择设备</option>
		    		<option value="7" <c:if test="${buttonObj[9] == '7' }">selected=selected</c:if>>项目分配</option>
		    		<option value="8" <c:if test="${buttonObj[9] == '8' }">selected=selected</c:if>>自动确认样品</option>
		    		<option value="9" <c:if test="${buttonObj[9] == '9' }">selected=selected</c:if>>施工单</option> -->
		    	</select>
		    </td>
		  </tr>
		  <tr>
		    <td align="right">操作类型：</td>
		    <td> 
		    	<select name="operateType" id="operateType" style="width:155px;">
		    		<option value="0" <c:if test="${buttonObj[10] == '0' }">selected=selected</c:if>>编辑</option>
		    		<option value="1" <c:if test="${buttonObj[10] == '1' }">selected=selected</c:if>>查看</option>
		    	</select>
		    </td>
		  </tr>
		  <tr>
		    <td align="right">过滤条件：</td>
		    <td align="left">
		    <div class="div">
				<textarea rows="8" cols="17" id="fitterCondition" name="fitterCondition" onkeydown="countlen(this);">${buttonObj[3]}</textarea>
			</div>
		    </td>
		  </tr>
		  <tr>
		    <td align="center" colspan="2" >
		    	<input type="button" id="saveBtn" value="提 交" class="form_bt_orange" />
		      	<input type="button" id="closeBtn" value="取 消" class="form_bt_grey" />
		    </td>
		  </tr>
		</table>
	</form>
  </body>
</html>
